% ************************************************************************ 
%     Module name   : Lynx Simulation - Track Mode Run                                                     
%                                                                          
%     Description   : This will run the Track mode on a specific target.                                                    
%                                                                          
%     $Header: /Lynx/SimulationFramework/RSP/IFS/IFSRun.m 2     15/10/08 16:08 Lwabeke $ 
%                                                                          
%    $Author: Lwabeke $	            
%                                                                         
%    $Revision: 2 $                
%                                                                         
% ************************************************************************
%     $History: IFSRun.m $ 
% 
%
% ************************************************************************
function [newTargetEst] = TrackMode_Run(time, param, radarSetup, oldTargetEst, worldState)
%global worldState;

newTargetEst = oldTargetEst;

targetID = oldTargetEst.id;

% for tgtCntr=1:size(worldState.Target,2)
%     if (worldState.Target(tgtCntr).id == targetID)
%         break;
%     end
% end
tgtCntr = targetID;
    
if (time > worldState.Target(tgtCntr).initTime) && (time < worldState.Target(tgtCntr).endTime)
    % Track mode will hit if time valid
    n = newTargetEst.NumMeasurements;
   newTargetEst.RangeEstStd = sqrt(n.^2 * newTargetEst.RangeEstStd.^2 + param.radarModes.TrackMode.hit.rangeEstStd.^2) ./ (n+1);
   newTargetEst.NumMeasurements = n+1;
else
   newTargetEst.RangeEstStd = newTargetEst.RangeEstStd * param.radarModes.TrackMode.miss.rangeEstStdFactor;
end

